package cn.enited.devtools.apiaggregator.dto;

import cn.enited.devtools.apiaggregator.anno.IsBizId;
import cn.enited.devtools.apiaggregator.validator.group.CreateValidationGroup;
import cn.enited.devtools.apiaggregator.validator.group.DeleteValidationGroup;
import cn.enited.devtools.apiaggregator.validator.group.UpdateValidationGroup;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

@Data
public class ProjectDto implements Serializable {
    private static final long serialVersionUID = -3961262185429102198L;

    @NotNull(groups = {UpdateValidationGroup.class, DeleteValidationGroup.class}, message = "缺少id标识")
    @IsBizId(groups = {UpdateValidationGroup.class, DeleteValidationGroup.class}, message = "无效的id")
    private Long bizId;

    @NotBlank(groups = {CreateValidationGroup.class}, message = "名称不能为空")
    private String name;

    @NotBlank(groups = {CreateValidationGroup.class, UpdateValidationGroup.class}, message = "描述不能为空")
    private String description;

    @NotNull(groups = {CreateValidationGroup.class, UpdateValidationGroup.class}, message = "生产环境配置不能为空")
    private ConfigurationDto productConfiguration;

    private ConfigurationDto testConfiguration;

    private ConfigurationDto trainingConfiguration;

    private Set<GlobalParameterDto> headerParameters;

    private Set<GlobalParameterDto> bodyParameters;

    private Date createDate;

    private Date updateDate;

    @Data
    public static class ConfigurationDto implements Serializable {
        private static final long serialVersionUID = -3649738908101161702L;

        private String defaultPathPrefix;

        private Map<String, String> specificPathPrefix;
    }

    @Data
    public static class GlobalParameterDto implements Serializable {
        private static final long serialVersionUID = 8822413404943429140L;

        private String name;

        private String type;

        private String value;

        private String remark;

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            GlobalParameterDto that = (GlobalParameterDto) o;
            return Objects.equals(name, that.name);
        }

        @Override
        public int hashCode() {
            return Objects.hash(name);
        }
    }
}
